//
//  JCClubInfoSectionHeader.m
//  SquashSpark
//
//  Created by 郭吉成 on 2017/11/27.
//  Copyright © 2017年 Coollang-YF. All rights reserved.
//

#import "JCClubInfoSectionHeader.h"
#import "UIView+JCDrawTool.h"

@interface JCClubInfoSectionHeader ()

@property (nonatomic, strong) UILabel *leftLabel;
@property (nonatomic, strong) UIButton *rightButton;
@property (nonatomic, strong) UIImageView *iconImage;

@end

@implementation JCClubInfoSectionHeader

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        if (_leftLabel == nil) {
            _leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, kYFScreenWidth, 55)];
            _leftLabel.font = kOpenSansFont(OpenSansRegular, 15);
            _leftLabel.textColor = [UIColor colorWithHex:0x999999];
            [self addSubview:_leftLabel];
        }
        if (_rightButton == nil) {

            _rightButton = [UIButton creatButtonTitle:@"" bgColor:[UIColor clearColor] textFont:kOpenSansFont(OpenSansBold, 14) textColor:[UIColor colorWithHex:0xffffff]];
            [_rightButton sizeToFit];
            _rightButton.frame = CGRectMake(kYFScreenWidth - _rightButton.bounds.size.width - 15, 0, _rightButton.bounds.size.width, 55);
            [_rightButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:_rightButton];
            
            _iconImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"club_choise_image"]];
            [_iconImage sizeToFit];
            _iconImage.center = CGPointMake(kYFScreenWidth - 0.5*_iconImage.bounds.size.width - 15, 27.5);
            _iconImage.hidden = YES;
            [self addSubview:_iconImage];
        }
        self.contentView.backgroundColor = kSeparationLineColor;
    }
    return self;
}

- (void)drawRect:(CGRect)rect {

}

- (void)buttonAction:(UIButton *)sender{
    if (_rightButtonAction && sender.titleLabel.text.length > 0) {
        _rightButtonAction(_buttonType);
    }
}

- (void)setleftTitle:(NSString *)title{
    _leftLabel.text = title;
}

- (void)setRightTitle:(NSString *)title{
    if (title.length <= 0) {
        _rightButton.hidden = YES;
    }else{
        _rightButton.hidden = NO;
    }
    [_rightButton setTitle:title forState:UIControlStateNormal];
    [_rightButton sizeToFit];
    _rightButton.frame = CGRectMake(kYFScreenWidth - _rightButton.bounds.size.width - 15, 0, _rightButton.bounds.size.width, 55);
}

- (void)setButtonType:(SectionButtonType)buttonType{
    _buttonType = buttonType;
    if (buttonType == SectionButtonTypeRank) {
        _iconImage.hidden = NO;
        _rightButton.frame = CGRectMake(kYFScreenWidth - _rightButton.bounds.size.width - 20 - _iconImage.bounds.size.width, 0, _rightButton.bounds.size.width, 55);
    }else{
        _iconImage.hidden = YES;
        _rightButton.frame = CGRectMake(kYFScreenWidth - _rightButton.bounds.size.width - 15, 0, _rightButton.bounds.size.width, 55);
    }
}

@end
